package Service;
import java.util.ArrayList;
import java.util.List;

import dao.PaperDao;
import pojo.PageBean;
import pojo.Paper;
public class PaperService {
	PaperDao cdao;
	public PageBean<Paper> show(int currentPage,int pageSize) {
		cdao = new PaperDao();
		PageBean<Paper> pb = new PageBean<Paper>();
		pb.setList(cdao.PageData(currentPage, pageSize));
		pb.setTotal(cdao.getTotal());
		int totalPage=(cdao.getTotal()%pageSize==0)?(cdao.getTotal()/pageSize):(cdao.getTotal()/pageSize+1);
		pb.setTotalPage(totalPage);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		return pb;
	}
	public List<Paper> showProductByType(int currentPage,int pageSize,int id){
		cdao = new PaperDao();
		List<Paper>list=new ArrayList<Paper>();
		list=cdao.showPaperByType(currentPage, pageSize, id);
		return list;
	}
	public int add(Paper p) {
		cdao=new PaperDao();
		int flag=cdao.add(p);
		return flag;
	}
	public int update(Paper p) {
		cdao=new PaperDao();
		int flag=cdao.update(p);
		return flag;
	}
	public Paper getPaper(int id) {
		cdao=new PaperDao();
		Paper p =cdao.getOnePaper(id);
		return p;
	}

}
